package com.yingside.net.chat2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //端口号不能超过65535，最好不要低于1024
        ServerSocket ss = new ServerSocket(8888);

        while(true){
            //接收客户端的连接
            Socket socket = ss.accept();
            System.out.println(socket.getInetAddress() + ":" + socket.getPort());

            BufferedReader br = null;

            br = new BufferedReader(new InputStreamReader(
                    socket.getInputStream()
            ));

            String s = null;

            PrintWriter serverOut = new PrintWriter(socket.getOutputStream(),true);

            while((s=br.readLine()) != null){
                System.out.println("服务器端打印:" + s);

                serverOut.println("服务器端反馈:" + s);
            }
        }

    }
}
